package com.jcodecraeer.xrecyclerview.progressindicator.indicator;

import ohos.agp.animation.Animator;
import ohos.agp.animation.AnimatorValue;
import ohos.agp.render.Arc;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.utils.RectFloat;

import java.util.ArrayList;
import java.util.List;

public class SemiCircleSpinIndicator extends BaseIndicatorController {
    @Override
    public void draw(Canvas canvas, Paint paint) {
        RectFloat rectF=new RectFloat(0,0,getWidth(),getHeight());
        Arc mArc = new Arc();
        mArc.setArc(-60,120,false);
        canvas.drawArc(rectF,mArc,paint);
    }

    @Override
    public List<Animator> createAnimation() {
        List<Animator> animators=new ArrayList<>();
        AnimatorValue scaleAnim = new AnimatorValue();
        scaleAnim.setLoopedCount(-1);
        scaleAnim.setDuration(600);
        scaleAnim.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
            @Override
            public void onUpdate(AnimatorValue animatorValue, float v) {
                getTarget().setRotation(v*360);
                postInvalidate();
            }
        });
        scaleAnim.start();
        animators.add(scaleAnim);
        return animators;
    }
}
